import { request, useUserStore, clearEmpty } from "jmash-core";
import qs from "qs";
import type { AxiosPromise } from "axios";
import type {
  ProcInstReq,
  FlowProcInstPage,
  FlowProcInstModel,
  FlowProcInstKey,
} from "../task/types";
import type { MonitorApi, FlowSuspendProcInstReq } from "./types";

class MonitorApiImpl implements MonitorApi {
  getKey(model: FlowProcInstModel): FlowProcInstKey {
    return {
      procInstId: model.id,
    } as FlowProcInstKey;
  }
  // 查询流程实例
  findPage(req: ProcInstReq): AxiosPromise<FlowProcInstPage> {
    const tenant = useUserStore().user.tenant;
    clearEmpty(req);
    return request({
      url: "/v1/flow/procinst/page/" + tenant,
      method: "get",
      params: req,
    });
  }
  // 暂停/恢复流程实例.
  suspendProcInst(data: FlowSuspendProcInstReq): AxiosPromise<boolean> {
    const tenant = useUserStore().user.tenant;
    clearEmpty(data);
    return request({
      url: "/v1/flow/procinst/suspend/" + tenant,
      method: "post",
      data: data,
    });
  }
}
const monitorApi = new MonitorApiImpl();

export { monitorApi };
